home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / tools / winlupe / source / win_lupe.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-22  |  34.6 KB  |  1,656 lines

  1.  
  2. /* #define SPEED 1 */
  3.  
  4. #ifdef SPEED
  5. long clock(void);
  6. char string[80];
  7. #endif
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <tos.h>
  13. #include <e_gem.h>
  14.  
  15. #define CICONBLK    ICONBLK
  16.  
  17. #ifdef GERMAN
  18.  
  19. #include "win_rsc.c"
  20. #include "win_rsc.h"
  21.  
  22. #else
  23.  
  24. #include "english.c"
  25. #include "english.h"
  26.  
  27. #endif
  28.  
  29. #define ELEMENTE NAME|CLOSER|SMALLER|FULLER|MOVER|SIZER|UPARROW|DNARROW|VSLIDE|HSLIDE|LFARROW|RTARROW
  30.  
  31. struct mem
  32. {
  33.     void    *memory;
  34.     void    *form;
  35. } buf[2];
  36.  
  37. typedef struct
  38. {
  39.     int     object[9],value[9];
  40.     int     shift,maske,faktor;
  41.     int     freq,dial;
  42.     GRECT    border;
  43.     int        xres,yres,mode;
  44. } _setup_;
  45.  
  46. _setup_ Setup =
  47. {
  48.     { REALTIME,MOUSE,WROUND,SLIDER,COMPT,INVERS,FOLLOW,BOXES,MONOFF },
  49.     { TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,TRUE,FALSE,FALSE},
  50.     2,0,3,
  51.     100,AUTO_DIAL,
  52.     {0,0,0,0},
  53.     0,0,0
  54. };
  55.  
  56. #define INFO_LEN sizeof(_setup_)
  57.  
  58. extern char *help[];
  59. extern int    help_lines;
  60.  
  61. WIN        *win;
  62.  
  63. int        vhandle;
  64. int        p_faktor,longs,il_offset,lines,line_h,old_line = -1,first_line = 0,scroll;
  65. int        z_x,z_y,z_w,z_h,xoff,yoff,open_cnt=0,new_freq,bytes,period;
  66. long    last_time;
  67.  
  68. long    zoom_x,zoom_y,zoom_w,zoom_h;
  69. long    tab_v[2048];
  70. char    *ind_tab[256];
  71. GRECT    rc_list[256];
  72. int        w_max_w,w_max_h;
  73.  
  74. boolean valid;
  75. DIAINFO    dialog_info,winlupe_info,help_info,opt_info,*return_info,*wins[8];
  76.  
  77. void    do_slide(OBJECT *,int,int,int,int);
  78. void    do_help(OBJECT *,int,int,int,int);
  79.  
  80. #define SCANUP        (72<<8)
  81. #define SCANDOWN    (80<<8)
  82. #define SCANLEFT    (75<<8)
  83. #define SCANRIGHT    (77<<8)
  84. #define CTRLLEFT    (115<<8)
  85. #define CTRLRIGHT    (116<<8)
  86. #define SCANHOME    (71<<8)
  87.  
  88. SLKEY sl_help_keys[] = {
  89. { SCANUP, 0, SL_UP },
  90. { SCANDOWN, 0, SL_DOWN },
  91. { SCANUP, K_RSHIFT|K_LSHIFT, SL_PG_UP },
  92. { SCANDOWN, K_RSHIFT|K_LSHIFT , SL_PG_DN },
  93. { SCANUP, K_CTRL, SL_START },
  94. { SCANDOWN, K_CTRL, SL_END },
  95. { SCANHOME, 0, SL_START },
  96. { SCANHOME, K_RSHIFT|K_LSHIFT, SL_END} };
  97.  
  98. SLKEY sl_freq_keys[] = {
  99. { SCANLEFT, 0, SL_UP },
  100. { SCANRIGHT, 0, SL_DOWN },
  101. { CTRLLEFT, K_CTRL, SL_START },
  102. { CTRLRIGHT, K_CTRL, SL_END }};
  103.  
  104. SLINFO sl_help = {&help_info,HELPPAR,HELPSLID,HELPUP,HELPDOWN,0,0,0,
  105.                   VERT_SLIDER,SL_LINEAR,100,0,do_help,&sl_help_keys[0],8};
  106. SLINFO *sl_help_list[] = {&sl_help,NULL};
  107.  
  108. SLINFO sl_freq = {&opt_info,PARENT,SLIDE,LEFT,RIGHT,99,1,100,
  109.                   HOR_SLIDER,SL_LINEAR,100,0,do_slide,&sl_freq_keys[0],4};
  110. SLINFO *sl_freq_list[] = {&sl_freq,NULL};
  111.  
  112. MFDB    source,buffer,zoomfm,stdfm;
  113. GRECT    window,old,zoom_area;
  114. OBJECT    *dialog_tree,*info_tree,*help_tree,*opt_tree;
  115.  
  116. char    entry[]        = "  WinLupe 6.70 ";
  117. char    *title        = entry+1;
  118. char    *version    = entry+10;
  119. char    *inf_file    = "A:\WIN_LUPE.INF";
  120.  
  121. #ifdef GERMAN
  122.  
  123. char    *init_err    = "[1][ | Fehler bei der | Initialisierung ! ][ Ok ]";
  124.  
  125. char    *win_err    = "Konnte kein Fenster|öffnen!]";
  126. char    *work_err    = "Konnte keine Work-|station öffnen!]";
  127. char    *mem_err    = "Nicht genug Speicher|für Bildschirmpuffer!";
  128. char    *file_err    = "Konnte WIN_LUPE.INF|nicht öffnen!";
  129. char    *rw_error    = "Schreib-/Lesefehler!";
  130.  
  131. #else
  132.  
  133. char    *init_err    = "[1][ | Error during | initialisation ! ][ Ok ]";
  134.  
  135. char    *win_err    = "No more windows|available!";
  136. char    *work_err    = "Couldn't open|workstation!";
  137. char    *mem_err    = "Not enough memory!";
  138. char    *file_err    = "Couldn't read|WIN_LUPE.INF!";
  139. char    *rw_error    = "Read-/Write-Error!";
  140.  
  141. #endif
  142.  
  143. int cdecl     draw_help(PARMBLK *);
  144. USERBLK         helpblk = {draw_help,0};
  145.  
  146. void    zoom_var(int,int,int,int *,long *);
  147. void    zoom_inter(int,int,int,int *,long *);
  148. void    zoom_pixel(int,int,int,int *,long *);
  149. void    init_zoom_var(void);
  150. void    init_zoom_pixel(int,int);
  151. long    cache_flush(void);
  152.  
  153. boolean alloc_buf(long,struct mem *);
  154. void    init_mfdb(int,int,int,void *,MFDB *);
  155. void    planes_tab(int);
  156. void    open_lupewindow(void);
  157. void    close_lupewindow(int);
  158. void    draw_window(GRECT *);
  159. void    calc_coords(boolean);
  160. void    set_slider(boolean,boolean,boolean);
  161. void    wind_size(GRECT *);
  162. void    dialog(void);
  163. void    l_min(long *,long);
  164. void    mouse_pos(long *,long *,int);
  165. void    scale(int *,int,int);
  166. void    load_info(void);
  167. void    save_info(void);
  168. int        do_messag(XEVENT *);
  169. int        init_msg(XEVENT *,int);
  170. void    get_value(boolean);
  171. void    set_value(boolean);
  172. void    dia_close(int);
  173. void    calc_xy(void);
  174. void    calc_wh(void);
  175. void    val_2_str(char *,int);
  176. void    calc_vars(void);
  177. void    slider_pos(void);
  178. void    set_window(boolean);
  179. void    exitus(void);
  180. void    info(void);
  181.  
  182. void    open_dial(OBJECT *,DIAINFO *,int,int);
  183. void    close_dial(DIAINFO *);
  184. int        error(char *);
  185.  
  186. int error(char *txt)
  187. {
  188.     return (xalert(1,0,X_ICN_ERROR,NULL,BUTTONS_CENTERED,TRUE,title,txt,"[Ok"));
  189. }
  190.  
  191. boolean alloc_buf(long size,struct mem *buf)
  192. {
  193.     register long adr;
  194.  
  195.     if ( (adr = (long) malloc(size)) > 0L )
  196.     {
  197.         buf->memory = (void *) adr;
  198.         adr             = (adr+255) & 0xffffff00L;
  199.         buf->form    = (void *) adr;
  200.         return(TRUE);
  201.     }
  202.     return(FALSE);
  203. }
  204.  
  205. void init_mfdb(int w,int h,int std,void *buf,MFDB *mfdb)
  206. {
  207.     mfdb->fd_addr     = buf;
  208.     mfdb->fd_w        = w;
  209.     mfdb->fd_h        = h;
  210.     mfdb->fd_wdwidth= w>>4;
  211.     mfdb->fd_stand    = std;
  212. }
  213.  
  214. void open_lupewindow()
  215. {
  216.     register long size;
  217.     register int fkt,wid,hei;
  218.     int d,x_res,y_res,x_max=0,y_max=0;
  219.  
  220.     wind_calc(WC_WORK,ELEMENTE,desk.g_x,desk.g_y,desk.g_w,desk.g_h,&d,&d,&x_res,&y_res);
  221.     for (fkt=2;fkt<=32;fkt++)
  222.     {
  223.         wid  = x_res/fkt;
  224.         wid += 15;
  225.         wid &= 0xfff0;
  226.         wid *= fkt;
  227.         if (wid>x_max)
  228.             x_max = wid;
  229.         hei  = ((y_res+fkt-1)/fkt)*fkt;
  230.         if (hei>y_max)
  231.             y_max = hei;
  232.     }
  233.  
  234.     size  = wid>>3;
  235.     size *= (long) y_max;
  236.     size *= (long) planes;
  237.     size += 1024;
  238.  
  239.     if (alloc_buf(size,&buf[0])==TRUE)
  240.     {
  241.         if (alloc_buf(size,&buf[1])==TRUE)
  242.         {
  243.             int work_out[57];
  244.             if (open_work(&vhandle,work_out))
  245.             {
  246.                 vs_clip (vhandle,1,(int *) &clip);
  247.  
  248.                 calc_vars();
  249.                 wind_calc(WC_WORK,ELEMENTE,Setup.border.g_x,Setup.border.g_y,Setup.border.g_w,Setup.border.g_h,
  250.                             &window.g_x,&window.g_y,&window.g_w,&window.g_h);
  251.                  xoff = window.g_x - Setup.border.g_x;
  252.                  yoff = window.g_y - Setup.border.g_y;
  253.                  calc_wh();
  254.                 calc_coords(TRUE);
  255.  
  256.                 if ((win=open_window(title,NULL,ELEMENTE,Setup.value[7],Setup.border.g_x,Setup.border.g_y,Setup.border.g_w,Setup.border.g_h))!=NULL)
  257.                 {
  258.                     if (menu_available)
  259.                         menu_ienable(menu,OPEN,0);
  260.  
  261.                     if ((Setup.value[0]==TRUE) && (Setup.value[6]==TRUE))
  262.                         mouse_pos(&zoom_x,&zoom_y,TRUE);
  263.                     else
  264.                         zoom_x = zoom_y = z_x = z_y = 0;
  265.  
  266.                     valid    = FALSE;
  267.                     old.g_x = -1;
  268.                     set_slider(FALSE,TRUE,FALSE);
  269.                     return;
  270.                 }
  271.                 else
  272.                 {
  273.                     close_work(vhandle);
  274.                     error(win_err);
  275.                 }
  276.             }
  277.             else
  278.                 error(work_err);
  279.             free(buf[1].memory);
  280.             free(buf[0].memory);
  281.             return;
  282.         }
  283.         else
  284.             free(buf[0].memory);
  285.     }
  286.     error(mem_err);
  287. }
  288.  
  289. void close_lupewindow(int close)
  290. {
  291.     if (win!=NULL)
  292.     {
  293.         if (close)
  294.             close_window(win,Setup.value[7]);
  295.         win = NULL;
  296.  
  297.         close_work(vhandle);
  298.  
  299.         free(buf[1].memory);
  300.         free(buf[0].memory);
  301.  
  302.         if (menu_available)
  303.             menu_ienable(menu,OPEN,1);
  304.     }
  305. }
  306.  
  307. void calc_coords(boolean size)
  308. {
  309.     register int max;
  310.  
  311.     if (window.g_x < (max = desk.g_x + 16 + xoff))
  312.         window.g_x = max;
  313.     window.g_x &= 0xfff0;
  314.  
  315.     if (Setup.shift<5)
  316.     {
  317.         window.g_w &= 0xfff0;
  318.         window.g_h &= Setup.maske;
  319.     }
  320.     else
  321.     {
  322.         switch (p_faktor)
  323.         {
  324.         case 2:
  325.         case 4:
  326.         case 8:
  327.         case 16:
  328.             window.g_w &= 0xfff0;
  329.             break;
  330.         case 6:
  331.         case 12:
  332.         case 24:
  333.             window.g_w = ((window.g_w/3) & 0xfff8)*3;
  334.             break;
  335.         case 32:
  336.             window.g_w &= 0xffe0;
  337.             break;
  338.         default:
  339.             window.g_w -= window.g_w % p_faktor;
  340.             break;
  341.         }
  342.         window.g_h -= window.g_h % p_faktor;
  343.     }
  344.  
  345.     if (window.g_w<96)
  346.         window.g_w = 96;
  347.  
  348.     while (window.g_h<96)
  349.         window.g_h += p_faktor;
  350.  
  351.     wind_calc(WC_BORDER,ELEMENTE,window.g_x,window.g_y,window.g_w,window.g_h,
  352.               &Setup.border.g_x,&Setup.border.g_y,&Setup.border.g_w,&Setup.border.g_h);
  353.  
  354.     if (size==TRUE)
  355.     {
  356.         register int max = desk.g_x + desk.g_w - 1 - Setup.border.g_x;
  357.         while (Setup.border.g_w>=max)
  358.         {
  359.             window.g_w -= p_faktor;
  360.             Setup.border.g_w -= p_faktor;
  361.         }
  362.  
  363.         max = desk.g_y + desk.g_h - 1 - Setup.border.g_y;
  364.         while (Setup.border.g_h>=max)
  365.         {
  366.             window.g_h -= p_faktor;
  367.             Setup.border.g_h -= p_faktor;
  368.         }
  369.     }
  370. }
  371.  
  372. void set_slider(boolean flag,boolean slide,boolean size)
  373. {
  374.     register int max;
  375.  
  376.     if (flag==TRUE && Setup.value[2]==TRUE)
  377.     {
  378.         calc_coords(size);
  379.         if (!(win->iconified & (ICONIFIED|ICFS)))
  380.             wind_set(win->handle,WF_CURRXYWH,Setup.border.g_x,
  381.                      Setup.border.g_y,Setup.border.g_w,Setup.border.g_h);
  382.     }
  383.     else
  384.         wind_get(win->handle,WF_CURRXYWH,&Setup.border.g_x,
  385.                  &Setup.border.g_y,&Setup.border.g_w,&Setup.border.g_h);
  386.     calc_wh();
  387.  
  388.     l_min(&zoom_x,(long) w_max_w * (long) p_faktor);
  389.     l_min(&zoom_y,(long) w_max_h * (long) p_faktor);
  390.     calc_xy();
  391.  
  392.     max=(z_w+15) & 0xfff0;
  393.  
  394.     init_mfdb(max,z_h,0,buf[0].form,&buffer);
  395.     init_mfdb(max,z_h,1,buf[1].form,&stdfm);
  396.     if (Setup.shift<5)
  397.         init_mfdb(max<<Setup.shift,z_h<<Setup.shift,1,buf[0].form,&zoomfm);
  398.     else
  399.         init_mfdb(max*p_faktor,z_h*p_faktor,1,buf[0].form,&zoomfm);
  400.  
  401.     source.fd_addr    = buf[1].form;
  402.     source.fd_w        = zoomfm.fd_w;
  403.     source.fd_h        = zoomfm.fd_h;
  404.     source.fd_wdwidth = zoomfm.fd_wdwidth;
  405.     source.fd_stand    = 0;
  406.  
  407.     if (!(win->iconified & (ICONIFIED|ICFS)))
  408.     {
  409.         if ((Setup.value[3]==TRUE) || (Setup.value[0]==FALSE) || (Setup.value[6]==FALSE))
  410.         {
  411.             register long pos;
  412.  
  413.             slider_pos();
  414.  
  415.             pos    = 1000 * (long) window.g_w;
  416.             pos    /= zoom_w;
  417.             wind_set(win->handle,WF_HSLSIZE,(int) pos);
  418.  
  419.             pos = 1000 * (long) window.g_h;
  420.             pos    /= zoom_h;
  421.             wind_set(win->handle,WF_VSLSIZE,(int) pos);
  422.         }
  423.         else if (slide==TRUE)
  424.         {
  425.             wind_set(win->handle,WF_HSLIDE,0);
  426.             wind_set(win->handle,WF_VSLIDE,0);
  427.             wind_set(win->handle,WF_HSLSIZE,1000);
  428.             wind_set(win->handle,WF_VSLSIZE,1000);
  429.         }
  430.     }
  431. }
  432.  
  433. void slider_pos()
  434. {
  435.     register long max,pos;
  436.  
  437.     l_min(&zoom_x,(max = (long) w_max_w * (long) p_faktor));
  438.     pos         = 1000 * zoom_x;
  439.     pos         /= max;
  440.     wind_set(win->handle,WF_HSLIDE,(int) pos);
  441.  
  442.     l_min(&zoom_y,(max = (long) w_max_h * (long) p_faktor));
  443.     pos            = 1000 * zoom_y;
  444.     pos            /= max;
  445.     wind_set(win->handle,WF_VSLIDE,(int) pos);
  446. }
  447.  
  448. void calc_wh()
  449. {
  450.     z_w=(window.g_w+p_faktor-1);
  451.     z_h=(window.g_h+p_faktor-1);
  452.  
  453.     if (Setup.shift<5)
  454.     {
  455.         z_w >>= Setup.shift;
  456.         z_h >>= Setup.shift;
  457.     }
  458.     else
  459.     {
  460.         z_w /= p_faktor;
  461.         z_h /= p_faktor;
  462.     }
  463.  
  464.     w_max_w = max_w - z_w + 1;
  465.     w_max_h = max_h - z_h + 1;
  466. }
  467.  
  468. void calc_xy()
  469. {
  470.     register long x=zoom_x,y=zoom_y;
  471.  
  472.     if (Setup.shift<5)
  473.     {
  474.         x >>= Setup.shift;
  475.         y >>= Setup.shift;
  476.     }
  477.     else
  478.     {
  479.         x /= p_faktor;
  480.         y /= p_faktor;
  481.     }
  482.  
  483.     z_x = (int) x;
  484.     z_y = (int) y;
  485. }
  486.  
  487. void draw_window(GRECT *area)
  488. {
  489.     int         pxy[8],d;
  490.     GRECT      work,wind = *area,mouse;
  491.     register GRECT *w_ptr = &work;
  492.     register int x,y,w,h,rc_idx = 0,*ptr;
  493.     boolean     update = (Setup.value[4]==TRUE || Setup.value[0]==FALSE);
  494.     boolean     hidem = (Setup.value[0]==FALSE || Setup.value[8]==TRUE),hidden;
  495.  
  496.     #ifdef SPEED
  497.     long alltime = clock(),time;
  498.     #endif
  499.  
  500.     if (update)
  501.         wind_update(BEG_UPDATE);
  502.  
  503.     ptr = &(rc_list[0].g_x);
  504.     wind_get(win->handle,WF_FIRSTXYWH,ptr,ptr+1,ptr+2,ptr+3);
  505.     while ((ptr[2]>0) && (ptr[3]>0))
  506.     {
  507.         if (win->iconified & (ICONIFIED|ICFS))
  508.             redraw_iconified(win->handle,iconified,(GRECT *) ptr);
  509.         else
  510.         {
  511.             ptr += 4;
  512.             rc_idx++;
  513.         }
  514.         wind_get(win->handle,WF_NEXTXYWH,ptr,ptr+1,ptr+2,ptr+3);
  515.     }
  516.  
  517.     if (!(win->iconified & (ICONIFIED|ICFS)))
  518.     {
  519.         if (valid==FALSE)
  520.         {
  521.             register int wid=(z_w+15)>>4,idx=rc_idx;
  522.             register int *orig;
  523.             register long *copy;
  524.             GRECT zoom;
  525.     
  526.             ptr = pxy;
  527.             *ptr++ = z_x;
  528.             *ptr++ = z_y;
  529.             *ptr++ = z_x+z_w-1;
  530.             *ptr++ = z_y+z_h-1;
  531.             *ptr++ = 0;
  532.             *ptr++ = 0;
  533.             *ptr++ = z_w-1;
  534.             *ptr   = z_h-1;
  535.     
  536.             if (pxy[2]>max_w)
  537.             {
  538.                 pxy[0] -= pxy[2]-max_w;
  539.                 pxy[2]    = max_w;
  540.             }
  541.     
  542.             if (pxy[3]>max_h)
  543.             {
  544.                 pxy[1] -= pxy[3]-max_h;
  545.                 pxy[3]    = max_h;
  546.             }
  547.     
  548.             if (Setup.value[1])
  549.                 vro_cpyfm(vhandle,3,pxy,screen,&buffer);
  550.             else
  551.             {
  552.                 graf_mouse(M_OFF,0L);
  553.                 vro_cpyfm(vhandle,3,pxy,screen,&buffer);
  554.                 graf_mouse(M_ON,0L);
  555.             }
  556.     
  557.             zoom.g_x = z_x;
  558.             zoom.g_y = z_y;
  559.             zoom.g_w = z_w;
  560.             zoom.g_h = z_h;
  561.             rc_intersect(&zoom_area,&zoom);
  562.             while (--idx>=0)
  563.             {
  564.                 work = rc_list[idx];
  565.                 if (rc_intersect(&zoom,w_ptr))
  566.                 {
  567.                     ptr = pxy;
  568.                     *ptr++ = pxy[4] = w_ptr->g_x - z_x;
  569.                     *ptr++ = pxy[5] = w_ptr->g_y - z_y;
  570.                     *ptr++ = pxy[6] = pxy[0] + w_ptr->g_w - 1;
  571.                     *ptr   = pxy[7] = pxy[1] + w_ptr->g_h - 1;
  572.                     vro_cpyfm(vhandle,0,pxy,&buffer,&buffer);
  573.                 }
  574.             }
  575.     
  576.             if (Setup.mode)
  577.             {
  578.                 orig = (int *)  buf[0].form;
  579.                 copy = (long *) buf[1].form;
  580.             }
  581.             else
  582.             {
  583.                 orig = (int *)  buf[1].form;
  584.                 copy = (long *) buf[0].form;
  585.                 vr_trnfm(vhandle,&buffer,&stdfm);
  586.             }
  587.     
  588.             #ifdef SPEED
  589.             time = clock();
  590.             #endif
  591.     
  592.             switch (Setup.mode)
  593.             {
  594.             case 2:
  595.                 if (planes<8)
  596.                     zoom_var(wid*planes,z_h,1,orig,copy);
  597.                 else
  598.                     zoom_pixel(wid,z_h,bytes,orig,copy);
  599.                 break;
  600.             case 3:
  601.                 zoom_inter(wid,z_h,planes,orig,copy);
  602.                 break;
  603.             default:
  604.                 zoom_var(wid,z_h,planes,orig,copy);
  605.             }
  606.     
  607.             #ifdef SPEED
  608.             time = clock() - time;
  609.             sprintf(string,"Zoom : %d ms",(int) (time*5));
  610.             v_gtext(vhandle,0,32,string);
  611.             #endif
  612.     
  613.             if (!Setup.mode)
  614.                 vr_trnfm(vhandle,&zoomfm,&source);
  615.             valid = TRUE;
  616.         }
  617.  
  618.         rc_intersect(&zoom_area,&wind);
  619.         while (--rc_idx>=0)
  620.         {
  621.             w_ptr = &rc_list[rc_idx];
  622.             if (rc_intersect(&wind,w_ptr))
  623.             {
  624.                 x = w_ptr->g_x-window.g_x;
  625.                 y = w_ptr->g_y-window.g_y;
  626.                 w = w_ptr->g_w-1;
  627.                 h = w_ptr->g_h-1;
  628.     
  629.                 ptr = pxy;
  630.                 *ptr++    = x;
  631.                 *ptr++    = y;
  632.                 *ptr++    = x+w;
  633.                 *ptr++    = y+h;
  634.                 *ptr++    = w_ptr->g_x;
  635.                 *ptr++    = w_ptr->g_y;
  636.                 *ptr++    = w_ptr->g_x+w;
  637.                 *ptr    = w_ptr->g_y+h;
  638.     
  639.                 if (hidem)
  640.                     graf_mouse(M_OFF,0l);
  641.                 else
  642.                 {
  643.                     graf_mkstate(&mouse.g_x,&mouse.g_y,&d,&d);
  644.                     mouse.g_x -= 32; mouse.g_y -= 32;
  645.                     mouse.g_w = mouse.g_h = 64;
  646.                     if (mouse.g_x<0)
  647.                     {
  648.                         mouse.g_w += mouse.g_x;
  649.                         mouse.g_x  = 0;
  650.                     }
  651.                     if (mouse.g_y<0)
  652.                     {
  653.                         mouse.g_h += mouse.g_y;
  654.                         mouse.g_y  = 0;
  655.                     }
  656.                     if (rc_intersect(w_ptr,&mouse))
  657.                     {
  658.                         hidden = TRUE;
  659.                         graf_mouse(M_OFF,0l);
  660.                     }
  661.                     else
  662.                         hidden = FALSE;
  663.                 }
  664.                 vro_cpyfm(vhandle,3,pxy,&source,screen);
  665.                 if (hidem || hidden)
  666.                     graf_mouse(M_ON,0l);
  667.             }
  668.         }
  669.     }
  670.  
  671.     if (update)
  672.         wind_update(END_UPDATE);
  673.  
  674.     #ifdef SPEED
  675.     alltime = clock() - alltime;
  676.     sprintf(string,"All : %d ms",(int) (alltime*5));
  677.     v_gtext(vhandle,120,32,string);
  678.     #endif
  679. }
  680.  
  681. int init_msg(XEVENT *evt,int available)
  682. {
  683.     if (win!=NULL && !win->iconified && Setup.value[0] && (available & MU_TIMER2) && get_dialog_info(NULL,NULL,NULL)==TRUE)
  684.     {
  685.         evt->ev_mt2hicount = 0;
  686.         evt->ev_mt2locount = period;
  687.         evt->ev_mt2last = last_time;
  688.         return (MU_MESAG|MU_KEYBD|MU_TIMER2);
  689.     }
  690.     else
  691.         return (MU_MESAG|MU_KEYBD);
  692. }
  693.  
  694. void open_dial(OBJECT *tree,DIAINFO *info,int center,int dial)
  695. {
  696.     SLINFO **slider;
  697.     wins[open_cnt++] = info;
  698.  
  699.     if (info==&opt_info)
  700.         slider = sl_freq_list;
  701.     else if (info==&help_info)
  702.         slider = sl_help_list;
  703.     else
  704.         slider = NULL;
  705.     open_dialog(tree,info,title,center,(center<0) ? FALSE : Setup.value[7],dial,0,slider);
  706. }
  707.  
  708. void close_dial(DIAINFO *info)
  709. {
  710.     register int i;
  711.  
  712.     for (i=0;i<open_cnt;i++)
  713.         if (wins[i]==info)
  714.             break;
  715.     open_cnt--;
  716.     for (;i<open_cnt;i++)
  717.         wins[i] = wins[i+1];
  718.  
  719.     close_dialog(info,Setup.value[7]);
  720. }
  721.  
  722. void dia_close(int button)
  723. {
  724.     close_dial(return_info);
  725.     opt_tree[button].ob_state &= ~DISABLED;
  726.     ob_draw_chg(&opt_info,button,NULL,FAIL,FALSE);
  727. }
  728.  
  729. void do_slide(OBJECT *obj,int pos,int prev,int max_pos,int top)
  730. {
  731.     new_freq=sl_freq.sl_pos+1;
  732.     val_2_str(obj->ob_spec.tedinfo->te_ptext,new_freq);
  733. }
  734.  
  735. int cdecl draw_help(PARMBLK *pb)
  736. {
  737.     register int cnt_lines,start_line = first_line,delta_lines = (first_line>old_line) ? (first_line - old_line) : (old_line - first_line);
  738.     register int x = pb->pb_x,y = pb->pb_y;
  739.  
  740.     v_set_text(small_font_id,small_font,-1,NULL);
  741.     if (!scroll || (pb->pb_y+pb->pb_h)>max_h || delta_lines>=(lines-3) || delta_lines<=0)
  742.         cnt_lines = lines;
  743.     else
  744.     {
  745.         register GRECT source;
  746.         register int dy = delta_lines*line_h;
  747.  
  748.         source.g_x = x;
  749.         source.g_y = y;
  750.         source.g_w = pb->pb_w;
  751.         source.g_h = pb->pb_h - dy;
  752.  
  753.         if (first_line>old_line)
  754.         {
  755.             source.g_y += dy;
  756.             rc_sc_copy(&source,x,y,3);
  757.             if (pb->pb_hc>pb->pb_h)
  758.                 start_line += lines - delta_lines;
  759.             else
  760.             {
  761.                 start_line += ((pb->pb_yc + pb->pb_hc - y)/line_h)-delta_lines;
  762.                 delta_lines++;
  763.             }
  764.         }
  765.         else
  766.         {
  767.             rc_sc_copy(&source,x,y + dy,3);
  768.             if (pb->pb_hc<=pb->pb_h)
  769.             {
  770.                 start_line += (pb->pb_yc - y)/line_h;
  771.                 delta_lines++;
  772.             }
  773.         }
  774.  
  775.         start_line = max(start_line,first_line);
  776.         cnt_lines = min(delta_lines,help_lines-start_line);
  777.  
  778.         if (start_line-first_line+cnt_lines>lines)
  779.             cnt_lines = lines-start_line+first_line;
  780.     }
  781.  
  782.     {
  783.         register GRECT clear;
  784.         register int index;
  785.  
  786.         y += (start_line-first_line)*line_h;
  787.  
  788.         clear.g_x = x;
  789.         clear.g_y = y;
  790.         clear.g_w = pb->pb_w;
  791.         clear.g_h = cnt_lines*line_h;
  792.         rc_intersect((GRECT *) &pb->pb_x,&clear);
  793.         rc_sc_clear(&clear);
  794.  
  795.         for (index=cnt_lines;--index>=0;y += line_h)
  796.             v_gtext(x_handle,x,y,help[start_line++]);
  797.     }
  798.     return(0);
  799. }
  800.  
  801. void do_help(OBJECT *obj,int pos,int prev,int max_pos,int top)
  802. {
  803.     old_line = first_line;
  804.     first_line = pos;
  805.  
  806.     scroll = top;
  807.     ob_draw_chg(&help_info,HELPVIEW,NULL,FAIL,top);
  808.     scroll = FALSE;
  809. }
  810.  
  811. void calc_vars()
  812. {
  813.     zoom_x = z_x;
  814.     zoom_y = z_y;
  815.     zoom_w = max_w+1;
  816.     zoom_h = max_h+1;
  817.  
  818.     if (Setup.shift<5)
  819.     {
  820.         p_faktor = 1<<Setup.shift;
  821.  
  822.         zoom_x <<= Setup.shift;
  823.         zoom_y <<= Setup.shift;
  824.         zoom_w <<= Setup.shift;
  825.         zoom_h <<= Setup.shift;
  826.     }
  827.     else
  828.     {
  829.         p_faktor = Setup.faktor;
  830.  
  831.         zoom_x  *= p_faktor;
  832.         zoom_y  *= p_faktor;
  833.         zoom_w  *= p_faktor;
  834.         zoom_h  *= p_faktor;
  835.     }
  836.  
  837.     longs = (p_faktor*(p_faktor-1))>>1;
  838.     il_offset = (planes*(p_faktor-1))<<1;
  839.  
  840.     if (Setup.mode==2)
  841.     {
  842.         if (planes<8)
  843.             planes_tab(planes);
  844.         else
  845.         {
  846.             long cpu;
  847.  
  848.             bytes = (planes+7)>>3;
  849.             init_zoom_pixel(bytes,Setup.value[5]);
  850.  
  851.             if (get_cookie('_CPU',&cpu)==TRUE && cpu>=20)
  852.                 Supexec(cache_flush);
  853.         }
  854.     }
  855.     else
  856.         planes_tab(1);
  857.  
  858.     Setup.maske  = ~(p_faktor-1);
  859. }
  860.  
  861. void dialog()
  862. {
  863.     if (!open_cnt)
  864.     {
  865.         register int obj,double_click;
  866.  
  867.         open_dial(dialog_tree,&dialog_info,TRUE,Setup.dial);
  868.         do
  869.         {
  870.             double_click = 0;
  871.             obj = X_Form_Do(&return_info);
  872.  
  873.             if (obj==W_ABANDON)
  874.                 break;
  875.             else if (obj!=W_CLOSED)
  876.             {
  877.                 double_click = (obj & 0x8000);
  878.                 obj ^= double_click;
  879.                 return_info->di_tree[obj].ob_state &= ~SELECTED;
  880.             }
  881.  
  882.             if (return_info==&winlupe_info)
  883.                 dia_close(INFOBUT);
  884.             else if (return_info==&help_info)
  885.                 dia_close(HELP);
  886.             else if (return_info==&opt_info)
  887.             {
  888.                 switch (obj)
  889.                 {
  890.                 case INFOBUT:
  891.                 case HELP:
  892.                     opt_tree[obj].ob_state |= DISABLED;
  893.                     ob_draw_chg(&opt_info,obj,NULL,FAIL,FALSE);
  894.                     if (obj==INFOBUT)
  895.                         open_dial(info_tree,&winlupe_info,TRUE,(Setup.dial!=FLY_DIAL) ? (AUTO_DIAL|MODAL) : FLY_DIAL);
  896.                     else
  897.                         open_dial(help_tree,&help_info,TRUE,Setup.dial);
  898.                     break;
  899.                 default:
  900.                     if (obj!=OPTCANCL)
  901.                         get_value(FALSE);
  902.                     else
  903.                         set_value(FALSE);
  904.                     calc_vars();
  905.  
  906.                     if (obj==OPTSET)
  907.                     {
  908.                         set_window(FALSE);
  909.                         ob_draw_chg(&opt_info,OPTSET,NULL,FAIL,FALSE);
  910.                     }
  911.                     else if (obj==SAVE)
  912.                     {
  913.                         if (dialog_info.di_flag>CLOSED)
  914.                         {
  915.                             get_value(TRUE);
  916.                             calc_vars();
  917.                         }
  918.                         set_window(FALSE);
  919.                         save_info();
  920.                         ob_draw_chg(&opt_info,SAVE,NULL,FAIL,FALSE);
  921.                     }
  922.                     else
  923.                     {
  924.                         close_dial(return_info);
  925.                         dialog_tree[SONSTIGE].ob_state &= ~DISABLED;
  926.                         ob_draw_chg(&dialog_info,SONSTIGE,NULL,FAIL,FALSE);
  927.                         if (obj!=OPTCANCL && Setup.dial==AUTO_DIAL)
  928.                         {
  929.                             switch (dialog_info.di_flag)
  930.                             {
  931.                             case OPENED:
  932.                             case FLYING:
  933.                                 close_dial(&dialog_info);
  934.                                 open_dial(dialog_tree,&dialog_info,FAIL,Setup.dial);
  935.                                 set_window(FALSE);
  936.                                 break;
  937.                             }
  938.                         }
  939.                     }
  940.                 }
  941.             }
  942.             else
  943.             {
  944.                 switch (obj)
  945.                 {
  946.                 case SONSTIGE:
  947.                     dialog_tree[SONSTIGE].ob_state |= DISABLED;
  948.                     ob_draw_chg(&dialog_info,SONSTIGE,NULL,FAIL,FALSE);
  949.                     open_dial(opt_tree,&opt_info,TRUE,Setup.dial);
  950.                     break;
  951.                 case CANCEL:
  952.                     close_dial(return_info);
  953.                     set_value(FAIL);
  954.                     calc_vars();
  955.                     set_window(FALSE);
  956.                     break;
  957.                 default:
  958.                     get_value(TRUE);
  959.                     calc_vars();
  960.  
  961.                     if (win==NULL)
  962.                     {
  963.                         if (obj==OKAY)
  964.                         {
  965.                             if (return_info->di_flag<WINDOW)
  966.                                 close_dial(return_info);
  967.                             open_lupewindow();
  968.                         }
  969.  
  970.                         if (obj!=SET)
  971.                             close_dial(return_info);
  972.                     }
  973.                     else
  974.                     {
  975.                         if (obj!=SET)
  976.                             close_dial(return_info);
  977.                         set_window(obj==SET ? FALSE : TRUE);
  978.                     }
  979.  
  980.                     if (obj==SET)
  981.                     {
  982.                         ob_draw_chg(&dialog_info,SET,NULL,FAIL,FALSE);
  983.                         ob_draw_chg(&dialog_info,FAKTOR,NULL,FAIL,FALSE);
  984.                     }
  985.                 }
  986.             }
  987.         } while (open_cnt>0);
  988.         dialog_tree[SONSTIGE].ob_state &= ~DISABLED;
  989.         opt_tree[INFOBUT].ob_state &= ~DISABLED;
  990.         opt_tree[HELP].ob_state &= ~DISABLED;
  991.         if (obj==W_ABANDON)
  992.             set_value(TRUE);
  993.         open_cnt = 0;
  994.     }
  995.     else if (dialog_info.di_flag==WINDOW)
  996.         wind_set(dialog_info.di_win->handle,WF_TOP);
  997.     else if (dialog_info.di_flag==CLOSED)
  998.         open_dial(dialog_tree,&dialog_info,TRUE,Setup.dial);
  999. }
  1000.  
  1001. void set_window(boolean top)
  1002. {
  1003.     if (win!=NULL && get_dialog_info(NULL,NULL,NULL)==TRUE)
  1004.     {
  1005.         if ((Setup.value[0]==TRUE) && (Setup.value[6]==TRUE))
  1006.             mouse_pos(&zoom_x,&zoom_y,TRUE);
  1007.         valid = FALSE;
  1008.         if (top==TRUE)
  1009.             wind_set(win->handle,WF_TOP);
  1010.         set_slider(TRUE,TRUE,TRUE);
  1011.         draw_window(&window);
  1012.     }
  1013. }
  1014.  
  1015. void planes_tab(int planes)
  1016. {
  1017.     register long zoom;
  1018.     register char *mem = (char *) tab_v,**ind = ind_tab;
  1019.     register int act,faktor,pixel,plane = planes,bits = 8;
  1020.     int         maske,index,bit,byte,shift = 8-plane,offset = p_faktor & 0x01;
  1021.     boolean     flag = Setup.value[5];
  1022.  
  1023.     {
  1024.         long cpu;
  1025.         init_zoom_var();
  1026.         if (get_cookie('_CPU',&cpu)==TRUE && cpu>=2)
  1027.             Supexec(cache_flush);
  1028.     }
  1029.  
  1030.     maske = ((1<<plane)-1)<<shift;
  1031.     for (index=0;index<256;index++)
  1032.     {
  1033.         *ind++  = mem;
  1034.         byte    = index;
  1035.         zoom = act = 0;
  1036.  
  1037.         if (flag)
  1038.             for(bit=bits;(bit-=plane)>=0;)
  1039.             {
  1040.                 pixel = ((byte & maske)^maske)>>shift;
  1041.                 byte <<= plane;
  1042.  
  1043.                 for (faktor=p_faktor;--faktor>=0;)
  1044.                 {
  1045.                     zoom <<= plane;
  1046.                     zoom  |= pixel;
  1047.  
  1048.                     act += plane;
  1049.                     while (act>=bits)
  1050.                         *mem++    = (char) (zoom >> (act-=bits));
  1051.                 }
  1052.             }
  1053.         else
  1054.             for(bit=bits;(bit-=plane)>=0;)
  1055.             {
  1056.                 pixel = (byte & maske)>>shift;
  1057.                 byte <<= plane;
  1058.  
  1059.                 for (faktor=p_faktor;--faktor>=0;)
  1060.                 {
  1061.                     zoom <<= plane;
  1062.                     zoom  |= pixel;
  1063.  
  1064.                     act += plane;
  1065.                     while (act>=bits)
  1066.                         *mem++    = (char) (zoom >> (act-=bits));
  1067.                 }
  1068.             }
  1069.         mem    += offset;
  1070.     }
  1071. }
  1072.  
  1073. void get_value(boolean flag)
  1074. {
  1075.     if (flag==TRUE)
  1076.     {
  1077.         register int i;
  1078.         register char *num;
  1079.  
  1080.         Setup.shift = ob_radio(dialog_tree,PFAKTOR,FAIL) + 1;
  1081.         for (i=0;i<=8;i++)
  1082.             Setup.value[i] = (dialog_tree[Setup.object[i]].ob_state & SELECTED) ? TRUE : FALSE;
  1083.  
  1084.         num = dialog_tree[FAKTOR].ob_spec.tedinfo->te_ptext;i=0;
  1085.         while (*num)
  1086.         {
  1087.             i *= 10;
  1088.             i += (*num++) - 48;
  1089.         }
  1090.         if (i<2)
  1091.             Setup.faktor = 2;
  1092.         else if (i>32)
  1093.             Setup.faktor = 32;
  1094.         else
  1095.             Setup.faktor = i;
  1096.         val_2_str(dialog_tree[FAKTOR].ob_spec.tedinfo->te_ptext,Setup.faktor);
  1097.         p_faktor = Setup.faktor;
  1098.     }
  1099.     else
  1100.     {
  1101.         Setup.mode = ob_radio(opt_tree,PZMODE,FAIL);
  1102.         Setup.dial = (opt_tree[WIND].ob_state & SELECTED) ? AUTO_DIAL : FLY_DIAL;
  1103.         Setup.freq = new_freq;
  1104.         period = (1000/new_freq)-9;
  1105.     }
  1106. }
  1107.  
  1108. void val_2_str(char *d,int val)
  1109. {
  1110.     register int div;
  1111.  
  1112.     if ((div=val/100)>0)
  1113.     {
  1114.         *d++ = (char) (div + 48);
  1115.         *d++ = (char) (((val -= div*100)/10) + 48);
  1116.     }
  1117.     else if ((div=val/10)>0)
  1118.         *d++ = (char) (div + 48);
  1119.     *d++ = (char) ((val % 10) + 48);
  1120.     *d = 0;
  1121. }
  1122.  
  1123. void set_value(boolean all)
  1124. {
  1125.     if (all)
  1126.     {
  1127.         register int i;
  1128.  
  1129.         new_freq = Setup.freq;
  1130.  
  1131.         ob_radio(dialog_tree,PFAKTOR,Setup.shift-1);
  1132.         for(i=0;i<=8;i++)
  1133.         {
  1134.             if (Setup.value[i])
  1135.                 dialog_tree[Setup.object[i]].ob_state |= SELECTED;
  1136.             else
  1137.                 dialog_tree[Setup.object[i]].ob_state &= ~SELECTED;
  1138.         }
  1139.         val_2_str(dialog_tree[FAKTOR].ob_spec.tedinfo->te_ptext,Setup.faktor);
  1140.     }
  1141.  
  1142.     if (all>=0)
  1143.     {
  1144.         ob_radio(opt_tree,PZMODE,Setup.mode);
  1145.  
  1146.         opt_tree[WIND].ob_state &= ~SELECTED;
  1147.         opt_tree[FLY].ob_state &= ~SELECTED;
  1148.  
  1149.         if (Setup.dial==AUTO_DIAL)
  1150.             opt_tree[WIND].ob_state |= SELECTED;
  1151.         else
  1152.             opt_tree[FLY].ob_state |= SELECTED;
  1153.  
  1154.         opt_info.di_tree = opt_tree;
  1155.         help_info.di_tree = help_tree;
  1156.  
  1157.         sl_freq.sl_pos = Setup.freq-1;
  1158.         val_2_str(opt_tree[SLIDE].ob_spec.tedinfo->te_ptext,Setup.freq);
  1159.         period = (1000/new_freq)-9;
  1160.  
  1161.         graf_set_slider(&sl_freq,opt_tree,GRAF_SET);
  1162.         graf_set_slider(&sl_help,help_tree,GRAF_SET);
  1163.     }
  1164. }
  1165.  
  1166. void exitus()
  1167. {
  1168.     close_lupewindow(TRUE);
  1169.  
  1170.     while (--open_cnt>=0)
  1171.         close_dialog(wins[open_cnt],FALSE);
  1172.  
  1173.     if (_app)
  1174.     {
  1175.         menu_bar(menu,0);
  1176.         exit_gem();
  1177.         Pterm(0);
  1178.     }
  1179. }
  1180.  
  1181. void info()
  1182. {
  1183.     if (winlupe_info.di_flag>=WINDOW)
  1184.         wind_set(winlupe_info.di_win->handle,WF_TOP);
  1185.     else if (winlupe_info.di_flag==CLOSED)
  1186.     {
  1187.         if (open_cnt>0)
  1188.         {
  1189.             if (opt_info.di_flag>CLOSED)
  1190.             {
  1191.                 opt_tree[INFOBUT].ob_state |= DISABLED;
  1192.                 ob_draw_chg(&opt_info,INFOBUT,NULL,FAIL,FALSE);
  1193.             }
  1194.             open_dial(info_tree,&winlupe_info,TRUE,(Setup.dial!=FLY_DIAL) ? (AUTO_DIAL|MODAL) : FLY_DIAL);
  1195.         }
  1196.         else 
  1197.             xdialog(info_tree,title,TRUE,Setup.value[7],(Setup.dial!=FLY_DIAL) ? (AUTO_DIAL|MODAL) : FLY_DIAL);
  1198.     }
  1199. }
  1200.  
  1201. int do_messag(XEVENT *event)
  1202. {
  1203.     register int ev = event->ev_mwich,speed,*msg = event->ev_mmgpbuf;
  1204.     register int used = 0;
  1205.  
  1206.     long max,new_pos;
  1207.     int    v_h,pos;
  1208.  
  1209.     if (ev & MU_TIMER2)
  1210.     {
  1211.         last_time = event->ev_mt2last;
  1212.  
  1213.         if (Setup.value[6]==TRUE)
  1214.         {
  1215.             long x = event->ev_mmox,y = event->ev_mmoy;
  1216.  
  1217.             mouse_pos(&x,&y,FALSE);
  1218.             if ((x!=zoom_x) || (y!=zoom_y))
  1219.             {
  1220.                 zoom_x = x;zoom_y = y;
  1221.                 if ((Setup.value[3]==TRUE) || (Setup.value[0]==FALSE) || (Setup.value[6]==FALSE))
  1222.                     slider_pos();
  1223.             }
  1224.         }
  1225.  
  1226.         valid = FALSE;
  1227.         draw_window(&window);
  1228.     }
  1229.  
  1230.     if (ev & MU_MESAG)
  1231.     {
  1232.         used |= MU_MESAG;
  1233.  
  1234.         switch (*msg)
  1235.         {
  1236.         case MN_SELECTED:
  1237.             menu_tnormal(menu,msg[3],1);
  1238.             switch (msg[4])
  1239.             {
  1240.             case INFOBOX:
  1241.                 info();
  1242.                 break;
  1243.             case SETUP:
  1244.                 dialog();
  1245.                 return(used);
  1246.             case QUIT:
  1247.                 exitus();
  1248.                 break;
  1249.             case OPEN:
  1250.                 if (win==NULL)
  1251.                 {
  1252.                     get_value(TRUE);
  1253.                     open_lupewindow();
  1254.                 }
  1255.                 break;
  1256.             }
  1257.             break;
  1258.         case AP_TERM:
  1259.         case AC_CLOSE:
  1260.             close_lupewindow(*msg==AP_TERM);
  1261.             break;
  1262.         case AC_OPEN:
  1263.             dialog();
  1264.             return(used);
  1265.         case WIN_CHANGED:
  1266.             if (win!=NULL && !win->iconified)
  1267.                 set_slider(FALSE,TRUE,FALSE);
  1268.             break;
  1269.         case WM_REDRAW:
  1270.             draw_window((GRECT *) (msg+4));
  1271.             break;
  1272.         case WM_TOPPED:
  1273.             wind_set(win->handle,WF_TOP);
  1274.             break;
  1275.         case WM_BOTTOMED:
  1276.             wind_set(win->handle,WF_BOTTOM);
  1277.             break;
  1278.         case WM_CLOSED:
  1279.             close_lupewindow(TRUE);
  1280.             break;
  1281.         case WM_FULLED:
  1282.             {
  1283.                 if (old.g_x>=desk.g_x && old.g_y>=desk.g_y &&
  1284.                      old.g_w<=desk.g_w && old.g_h<=desk.g_h)
  1285.                 {
  1286.                     wind_size(&old);
  1287.                     old.g_x = -1;
  1288.                 }
  1289.                 else
  1290.                 {
  1291.                     old    = Setup.border;
  1292.                     wind_size(&desk);
  1293.                 }
  1294.                 valid = FALSE;
  1295.                 set_slider(TRUE,FALSE,TRUE);
  1296.             }
  1297.             break;
  1298.         case WM_ARROWED:
  1299.             if ((Setup.value[0]==FALSE) || (Setup.value[6]==FALSE))
  1300.             {
  1301.                 max = p_faktor;
  1302.                 switch(msg[4])
  1303.                 {
  1304.                 case WA_UPPAGE:
  1305.                 case WA_DNPAGE:
  1306.                 case WA_UPLINE:
  1307.                 case WA_DNLINE:
  1308.                      max    *= (long) w_max_h;
  1309.                     v_h = TRUE;
  1310.                     break;
  1311.                 default:
  1312.                     max    *= (long) w_max_w;
  1313.                     v_h = FALSE;
  1314.                     break;
  1315.                 }
  1316.  
  1317.                 for (;;)
  1318.                 {
  1319.                     speed = (winx && msg[5]<0) ? -msg[5] : 1;
  1320.  
  1321.                     switch(msg[4])
  1322.                     {
  1323.                     case WA_UPPAGE:
  1324.                         zoom_y -= window.g_h*speed;
  1325.                         if (zoom_y<0) zoom_y=0;
  1326.                         break;
  1327.                     case WA_DNPAGE:
  1328.                           zoom_y += window.g_h*speed;
  1329.                         l_min(&zoom_y,max);
  1330.                         break;
  1331.                     case WA_UPLINE:
  1332.                           zoom_y -= p_faktor*speed;
  1333.                         if (zoom_y<0) zoom_y=0;
  1334.                         break;
  1335.                     case WA_DNLINE:
  1336.                           zoom_y += p_faktor*speed;
  1337.                         l_min(&zoom_y,max);
  1338.                         break;
  1339.                     case WA_LFPAGE:
  1340.                           zoom_x -= window.g_w*speed;
  1341.                         if (zoom_x<0) zoom_x=0;
  1342.                         break;
  1343.                     case WA_RTPAGE:
  1344.                           zoom_x += window.g_w*speed;
  1345.                         l_min(&zoom_x,max);
  1346.                         break;
  1347.                     case WA_LFLINE:
  1348.                           zoom_x -= p_faktor*speed;
  1349.                         if (zoom_x<0) zoom_x=0;
  1350.                         break;
  1351.                     case WA_RTLINE:
  1352.                           zoom_x += p_faktor*speed;
  1353.                         l_min(&zoom_x,max);
  1354.                         break;
  1355.                     }
  1356.  
  1357.                     if (winx && msg[7]<0)
  1358.                     {
  1359.                         msg[4] = msg[6];
  1360.                         msg[5] = msg[7];
  1361.                         msg[7] = 0;
  1362.                     }
  1363.                     else
  1364.                         break;
  1365.                 }
  1366.  
  1367.                 if (v_h == TRUE)
  1368.                 {
  1369.                     new_pos            = 1000 * zoom_y;
  1370.                     new_pos            /= max;
  1371.                     wind_set(win->handle,WF_VSLIDE,(int) new_pos);
  1372.                 }
  1373.                 else
  1374.                 {
  1375.                     new_pos            = 1000 * zoom_x;
  1376.                     new_pos            /= max;
  1377.                     wind_set(win->handle,WF_HSLIDE,(int) new_pos);
  1378.                 }
  1379.                 valid = FALSE;
  1380.                 calc_xy();
  1381.                 draw_window(&window);
  1382.             }
  1383.             break;
  1384.         case WM_HSLID:
  1385.             if ((Setup.value[0] == FALSE) || (Setup.value[6]==FALSE))
  1386.             {
  1387.                 pos = msg[4];
  1388.                 wind_set(win->handle,WF_HSLIDE,pos);
  1389.                 zoom_x=(int) (((long) (zoom_w-window.g_w)*pos)/1000);
  1390.                 valid = FALSE;
  1391.                 calc_xy();
  1392.                 draw_window(&window);
  1393.             }
  1394.             break;
  1395.         case WM_VSLID:
  1396.             if ((Setup.value[0] == FALSE) || (Setup.value[6]==FALSE))
  1397.             {
  1398.                 pos = msg[4];
  1399.                 wind_set(win->handle,WF_VSLIDE,pos);
  1400.                 zoom_y=(int) (((long) (zoom_h-window.g_h)*pos)/1000);
  1401.                 valid = FALSE;
  1402.                 calc_xy();
  1403.                 draw_window(&window);
  1404.             }
  1405.             break;
  1406.         case WM_MOVED:
  1407.         case WM_SIZED:
  1408.             wind_size((GRECT *) (msg+4));
  1409.             old.g_x = -1;
  1410.             valid    = FALSE;
  1411.             set_slider(TRUE,FALSE,*msg==WM_MOVED ? FALSE : TRUE);
  1412.             break;
  1413.         default:
  1414.             used &= ~MU_MESAG;
  1415.         }
  1416.     }
  1417.  
  1418.     if (ev & MU_KEYBD)
  1419.     {
  1420.         int ascii = scan_2_ascii(event->ev_mkreturn,event->ev_mmokstate);
  1421.  
  1422.         if (event->ev_mmokstate & K_ALT)
  1423.         {
  1424.             if (ascii=='P')
  1425.             {
  1426.                 used |= MU_KEYBD;
  1427.                 dialog();
  1428.                 return(used);
  1429.             }
  1430.         }
  1431.         else if (event->ev_mmokstate & K_CTRL)
  1432.         {
  1433.             used |= MU_KEYBD;
  1434.  
  1435.             switch (ascii)
  1436.             {
  1437.             case 'I':
  1438.                 info();
  1439.                 break;
  1440.             case 'Q':
  1441.                 exitus();
  1442.                 break;
  1443.             case 'O':
  1444.                 if (win==NULL)
  1445.                 {
  1446.                     get_value(TRUE);
  1447.                     open_lupewindow();
  1448.                 }
  1449.                 break;
  1450.             default:
  1451.                 used &= ~MU_KEYBD;
  1452.             }
  1453.         }
  1454.     }
  1455.  
  1456.     return (used);
  1457. }
  1458.  
  1459. void wind_size(GRECT *new)
  1460. {
  1461.     wind_calc(WC_WORK,ELEMENTE,new->g_x,new->g_y,new->g_w,new->g_h,
  1462.                       &window.g_x,&window.g_y,&window.g_w,&window.g_h);
  1463.     if ((win->iconified & (ICONIFIED|ICFS)) && Setup.value[2]==FALSE)
  1464.         wind_set(win->handle,WF_CURRXYWH,new->g_x,new->g_y,new->g_w,new->g_h);
  1465. }
  1466.  
  1467. void l_min(register long *var,register long val)
  1468. {
  1469.     if ((*var)>val)
  1470.         *var = val;
  1471. }
  1472.  
  1473. void mouse_pos(register long *x,register long *y,int pos)
  1474. {
  1475.     int    sx,sy,dummy;
  1476.  
  1477.     if (pos)
  1478.     {
  1479.         graf_mkstate(&sx,&sy,&dummy,&dummy);
  1480.         *x = sx - (z_w>>1);
  1481.         *y = sy - (z_h>>1);
  1482.     }
  1483.     else
  1484.     {
  1485.         *x -= (z_w>>1);
  1486.         *y -= (z_h>>1);
  1487.     }
  1488.  
  1489.     if ((*x)<0)
  1490.         *x=0;
  1491.     else
  1492.         l_min(x,w_max_w);
  1493.  
  1494.     if ((*y)<0)
  1495.         *y=0;
  1496.     else
  1497.         l_min(y,w_max_h);
  1498.  
  1499.     z_x = (int) *x;
  1500.     z_y = (int) *y;
  1501.  
  1502.     if (Setup.shift<5)
  1503.     {
  1504.         *x <<= Setup.shift;
  1505.         *y <<= Setup.shift;
  1506.     }
  1507.     else
  1508.     {
  1509.         *x *= p_faktor;
  1510.         *y *= p_faktor;
  1511.     }
  1512. }
  1513.  
  1514. void scale(int *var,int omax,int nmax)
  1515. {
  1516.     register long new=*var;
  1517.     new    *= nmax;
  1518.     *var = (int) (new/omax);
  1519. }
  1520.  
  1521. void load_info()
  1522. {
  1523.     char file[256];
  1524.     int     x_res = (max_w+16) & 0xfff0 , y_res = max_h+1;
  1525.      int  w = desk.g_w>>1,h = (desk.g_h>>1)-4;
  1526.  
  1527.     dialog_tree    = (OBJECT *) rs_trindex[DIALOG];
  1528.     info_tree    = (OBJECT *) rs_trindex[INFODIA];
  1529.     help_tree    = (OBJECT *) rs_trindex[HELPDIA];
  1530.     opt_tree    = (OBJECT *) rs_trindex[OPTIONEN];
  1531.     menu        = (OBJECT *) rs_trindex[MENU];
  1532.     iconified    = (OBJECT *) rs_trindex[WINICON];
  1533.  
  1534.     info_tree[DATE].ob_spec.tedinfo->te_ptext = __DATE__;
  1535.     strcpy(ob_get_text(info_tree,VERS,0)+8,version);
  1536.     wind_calc(WC_WORK,ELEMENTE,desk.g_x+w,desk.g_y+h,w,h,&window.g_x,&window.g_y,&window.g_w,&window.g_h);
  1537.  
  1538.     {
  1539.         register OBJECT *obj = help_tree + HELPVIEW;
  1540.         register int i;
  1541.  
  1542.         line_h = gr_sh+2;
  1543.         obj->ob_type = G_USERDEF;
  1544.         obj->ob_spec.userblk = &helpblk;
  1545.  
  1546.         i = obj->ob_height;
  1547.         sl_help.sl_page = lines = (i/line_h)-1;
  1548.         sl_help.sl_max = help_lines;
  1549.         obj->ob_y += (i - (obj->ob_height = lines*line_h))>>1;
  1550.  
  1551.         obj = help_tree + HELPPAR;
  1552.         obj->ob_y++;
  1553.         obj->ob_height -= 2;
  1554.     }
  1555.  
  1556.     strcpy(file,inf_file+2);
  1557.     if (shel_find(file))
  1558.     {
  1559.         int handle = open(file,O_RDONLY);
  1560.         if (handle>0)
  1561.         {
  1562.             if (read(handle,&Setup,INFO_LEN)<INFO_LEN)
  1563.                 error(rw_error);
  1564.             else
  1565.             {
  1566.                 scale(&Setup.border.g_x,Setup.xres,x_res);
  1567.                 scale(&Setup.border.g_y,Setup.yres,y_res);
  1568.                 scale(&Setup.border.g_w,Setup.xres,x_res);
  1569.                 scale(&Setup.border.g_h,Setup.yres,y_res);
  1570.                 wind_calc(WC_WORK,ELEMENTE,Setup.border.g_x,Setup.border.g_y,
  1571.                           Setup.border.g_w,Setup.border.g_h,
  1572.                             &window.g_x,&window.g_y,&window.g_w,&window.g_h);
  1573.             }
  1574.             close(handle);
  1575.         }
  1576.     }
  1577.  
  1578.     if (Setup.shift<5)
  1579.         p_faktor = 1<<Setup.shift;
  1580.     else
  1581.         p_faktor = Setup.faktor;
  1582.     Setup.maske     = ~(p_faktor-1);
  1583.     calc_coords(FALSE);
  1584.  
  1585.     if (planes<8 && planes!=1 && planes!=2 && planes!=4)
  1586.     {
  1587.         opt_tree[PIXELPCK].ob_state |= DISABLED;
  1588.         if (Setup.mode==2)
  1589.             Setup.mode = 0;
  1590.     }
  1591.  
  1592.     set_value(TRUE);
  1593.  
  1594.     source.fd_nplanes = buffer.fd_nplanes = zoomfm.fd_nplanes = stdfm.fd_nplanes = planes;
  1595.     Setup.xres    = x_res; Setup.yres    = y_res;
  1596.     zoom_area.g_x = zoom_area.g_y = 0;
  1597.     zoom_area.g_w = max_w+1;
  1598.     zoom_area.g_h = max_h+1;
  1599.     dialog_info.di_flag = help_info.di_flag = winlupe_info.di_flag = CLOSED;
  1600. }
  1601.  
  1602. void save_info()
  1603. {
  1604.     int     handle;
  1605.     char *file = inf_file;
  1606.  
  1607.     if (_app)
  1608.         file += 2;
  1609.     else
  1610.     {
  1611.         long ssp;
  1612.  
  1613.         ssp = Super(NULL);
  1614.         *file = (char) (*((int *) 0x446)+65);
  1615.         Super((void *) ssp);
  1616.     }
  1617.  
  1618.     if ((handle = open(file,O_WRONLY|O_CREAT)) > 0)
  1619.     {
  1620.         if (write(handle,&Setup,INFO_LEN)<INFO_LEN)
  1621.             error(rw_error);
  1622.         close(handle);
  1623.     }
  1624.     else
  1625.         error(file_err);
  1626. }
  1627.  
  1628. void main()
  1629. {
  1630.     #ifdef GERMAN
  1631.     if (init_gem(entry,"WinLupe\0XDSC\0"\
  1632.                        "1Bildschirmlupe\0","WIN_LUPE",0,0,0)==TRUE)
  1633.     #else
  1634.     if (init_gem(entry,"WinLupe\0XDSC\0"\
  1635.                        "1Magnifying glass\0","WIN_ENG",0,0,0)==TRUE)
  1636.     #endif
  1637.     {
  1638.         wind_update(BEG_UPDATE);
  1639.  
  1640.         Event_Handler(init_msg, do_messag);
  1641.         CycleCloseWindows('W','U',WECHSELN,CLOSE);
  1642.  
  1643.         dial_options(TRUE,TRUE,FALSE,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE);
  1644.         rsrc_init(NUM_TREE,NUM_OBS,NUM_FRSTR,NUM_FRIMG,TEST_SCALING|DARK_SCALING,rs_strings,rs_frstr,rs_bitblk,
  1645.                   rs_frimg,rs_iconblk,rs_tedinfo,rs_object,(OBJECT **) rs_trindex,(RS_IMDOPE *) rs_imdope,8,16);
  1646.         load_info();
  1647.         menu_install(menu,TRUE);
  1648.  
  1649.         wind_update(END_UPDATE);
  1650.  
  1651.         Event_Multi(NULL);
  1652.     }
  1653.     else
  1654.         form_alert(1,init_err);
  1655. }
  1656.